package 链表;

public class 链表倒数第k个节点 {

    public ListNode getKthFromEnd(ListNode head, int k) {
          ListNode cur=head;
          int num=0;
          while (cur!=null){
              num++;
              cur=cur.next;
          }
        int i = num - k;
        cur=head;
        for (int j = 0; j < i; j++) {
            cur=cur.next;
        }
        return cur;
    }
}
